package router

import (
	"github.com/gin-contrib/sessions"
	sessions_redis "github.com/gin-contrib/sessions/redis"
	"github.com/gin-gonic/gin"
	"godemo/config"
	"godemo/controllers"
	"godemo/pkg/logger"
)

func Router() *gin.Engine {
	r := gin.Default()

	// 日志
	r.Use(gin.LoggerWithConfig(logger.LoggerToFile()))
	r.Use(logger.Recover)

	// session (redis)
	store, _ := sessions_redis.NewStore(10, "tcp", config.RedisAddress, "", []byte("secret"))
	r.Use(sessions.Sessions("mysession", store))

	user := r.Group("/user")
	{
		user.GET("/info/:id", controllers.UserController{}.GetUserInfo)

		user.POST("/list", controllers.UserController{}.GetList)

		user.PUT("/add", controllers.UserController{}.AddUser)

		user.POST("/update", controllers.UserController{}.UpdateUser)

		user.POST("/delete", controllers.UserController{}.DeleteUser)

		user.POST("/userList", controllers.UserController{}.GetUserList)

		/*user.DELETE("/delete", func(c *gin.Context) {
			c.String(http.StatusOK, "user delete")
		})*/

		user.POST("/register", controllers.UserController{}.Register)
		user.POST("/login", controllers.UserController{}.Login)
	}

	player := r.Group("/player")
	{
		player.POST("/list", controllers.PlayerController{}.FindPlayerList)
	}

	vote := r.Group("/vote")
	{
		vote.POST("/add", controllers.VoteController{}.AddVote)
	}

	return r
}
